home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 20-NetworkServices / ftp / ftp-config.frm.z / ftp-config.frm
Encoding:
Text File  |  2002-06-12  |  9.6 KB  |  334 lines

  1. #!/usr/bin/perl5
  2. #
  3. # ftp-config.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: ftp-config.frm,v 1.32 1997/11/17 19:06:23 shotes Exp $
  21.  
  22. # Form validation:  Inactivity timeout > 60
  23. #
  24. # Configuration file:  /etc/inetd.conf
  25.  
  26. *MINTIMEOUT = \240;
  27. *MAXTIMEOUT = \7200;
  28.  
  29. require "/usr/OnRamp/lib/OnRamp.pm";
  30. require "/usr/OnRamp/lib/java.pm";
  31.  
  32. $myname = "ftp-config.cgi";
  33. $help_page = "ftp-config-help.html";
  34. $conf = "/etc/inetd.conf";
  35. $dummy = "/etc/inetd.conf.tmp";
  36.  
  37. $title = "FTP Server";
  38.  
  39. if ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla\/2/) { $br_index = 1; }
  40. else { $br_index = 0; }
  41.  
  42. $js = 
  43. "br_index = $br_index;
  44. $js_check_int
  45. $js_standard
  46. $js_error_box
  47. $js_help
  48. function checkForm(form) {
  49.     if (form.eftp[br_index].checked) {
  50.         if (!testTimeout(form)) return (false);
  51.     } return (true);
  52. }
  53. function testTimeout(form) {
  54.     Ctrl = form.dto;
  55.     start = 0;  
  56.     while (Ctrl.value.charAt(start) == ' ') { start++; }
  57.     end = Ctrl.value.length-1; while (Ctrl.value.charAt(end) == ' ') { end--; }
  58.     time = Ctrl.value.substring(start,end+1);
  59.     for(i = 0; i < time.length; i++) { 
  60.         num = parseInt(time.charAt(i)); 
  61.         if (! checkInt(num, 10)) { 
  62.             errorBox (Ctrl, \"Timeout must be an integer value.\"); 
  63.             return (false); 
  64.         } 
  65.     }
  66.     num = parseInt(time);
  67.     if (num < 240 || num > 7200) { 
  68.         errorBox (Ctrl, \"Inactivity timeout must be between \\n240 and 7200 seconds.\"); 
  69.         return (false); 
  70.     }
  71.     return (true);
  72. }";
  73.  
  74.  
  75. print "Content-type: text/html\n\n";
  76.  
  77. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  78. @fields = split('&',$buffer);
  79.  
  80. &getValues;
  81.  
  82. foreach (@fields) {
  83.   @line = split('=',$_);
  84.   $line[1] =~ tr/+/ /; 
  85.   $fld{$line[0]} = $line[1];
  86.   }
  87.  
  88. if (%fld) {
  89.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  90.     $help =~ s/cgi$/hlp/;
  91.     exec $help if ($fld{'help'} eq "Help");
  92.  
  93.     if ($fld{'doit'} eq 'Ok') {
  94.         &formValidation;
  95.         if ($fld{'eftp'} eq 'Yes') { &enableFTP; }
  96.         else { &disableFTP; }
  97.     &getValues;
  98.     }
  99. }
  100.  
  101. &generic;
  102.  
  103. sub formValidation {
  104.     if ($fld{'dto'}) {
  105.         local ($error) = &check_int($fld{'dto'}, $MINTIMEOUT, $MAXTIMEOUT);
  106.  
  107.         &error("Timeout must be an integer value") if $error == 1;
  108.  
  109.         &error("Inactivity timeout must be between $MINTIMEOUT and $MAXTIMEOUT seconds.")
  110.             if $error > 1;
  111.     }
  112.     else { $fld{'dto'} = 900; } 
  113. }
  114.  
  115. sub error {
  116.     &error_block($_[0]);
  117.     $val{'dto'} = $fld{'dto'};
  118.     $val{'logf'} = $fld{'logf'};    
  119.     $val{'eftp'} = $fld{'eftp'};    
  120.     &generic;
  121.     exit 0;
  122. }
  123.  
  124. sub enableFTP {
  125.     $value = "ftp\tstream\ttcp\tnowait\troot\t/usr/etc/ftpd\tftpd";
  126.     if ($fld{'logf'} eq 'Yes') { $value .= " -l"; }
  127.     if ($fld{'dto'} ne '900') { 
  128.         $value .= " -t" . $fld{'dto'}; }
  129.  
  130.     $or = $fld{'or'};
  131.     $ow = $fld{'ow'};
  132.     $oe = $fld{'oe'};
  133.  
  134.     $gr = $fld{'gr'};
  135.     $gw = $fld{'gw'};
  136.     $ge = $fld{'ge'};
  137.  
  138.     $tr = $fld{'tr'};
  139.     $tw = $fld{'tw'};
  140.     $te = $fld{'te'};
  141.  
  142.     $mask = &args_to_umask;
  143.  
  144.     if ($mask ne '022') { 
  145.         $value .= " -u" . $mask; }
  146.     
  147.     &putEntry($conf,"ftp",$value);
  148.     system("/etc/killall", "-HUP", "inetd");
  149.  
  150.     $message = "FTP daemon enabled.";
  151. }
  152.  
  153. sub disableFTP {
  154.     if ($val{'eftp'} eq "Yes") { 
  155.         &commentEntry($conf,"ftp"); 
  156.     system("/etc/killall", "-HUP", "inetd");
  157.  
  158.         $message = "FTP daemon disabled.";
  159.     }
  160. }
  161.  
  162. sub commentEntry {
  163.     local($file) = $_[0];
  164.     local($entry) = $_[1];
  165.     local($len) = length($entry);
  166.  
  167.     open(IN,"< $file");
  168.     open(OUT,"> $dummy");
  169.     while(<IN>) {
  170.         if ($entry eq substr($_,0,$len)) {
  171.             print OUT "# ",$_;
  172.         } else { print OUT $_; }
  173.     }
  174.     close(IN);
  175.     close(OUT);
  176.     rename($dummy,$file) || &error("Unable to rename to $file");
  177. }
  178.  
  179. sub putEntry { 
  180.     local($file) = $_[0];
  181.     local($key) = $_[1];
  182.     local($val) = $_[2];
  183.  
  184.     open(IN,"< $file");
  185.     open(OUT,"> $dummy");
  186.     local($found) = 0;
  187.     while(<IN>) {
  188.         if (/^$key/ || /^#\s*$key/) {
  189.             print OUT $val,"\n";
  190.             $found = 1;
  191.         } else { print OUT $_; }
  192.     }
  193.     if ($found == 0) { print OUT $val,"\n"; }
  194.     close(IN);
  195.     close(OUT);
  196.     rename($dummy,$file) || &error("Unable to rename to $file");
  197. }
  198.  
  199. sub umask_to_args {
  200.     local($toct);
  201.     $toct = oct($_[0]);
  202.  
  203.     @otdef = @owdef = @grdef = ();
  204.  
  205.     if (!($toct & 0400)) { $val{'or'} = ""; } else { $val{'or'} = "on"; }
  206.     if (!($toct & 0200)) { $val{'ow'} = ""; } else { $val{'ow'} = "on"; }
  207.     if (!($toct & 0100)) { $val{'oe'} = ""; } else { $val{'oe'} = "on"; }
  208.  
  209.     if (!($toct & 0040)) { $val{'gr'} = ""; } else { $val{'gr'} = "on"; }
  210.     if (!($toct & 0020)) { $val{'gw'} = ""; } else { $val{'gw'} = "on"; }
  211.     if (!($toct & 0010)) { $val{'ge'} = ""; } else { $val{'ge'} = "on"; }
  212.  
  213.     if (!($toct & 0004)) { $val{'tr'} = ""; } else { $val{'tr'} = "on"; }
  214.     if (!($toct & 0002)) { $val{'tw'} = ""; } else { $val{'tw'} = "on"; }
  215.     if (!($toct & 0001)) { $val{'te'} = ""; } else { $val{'te'} = "on"; }
  216. }
  217.  
  218. sub args_to_umask {
  219.     $umask = 0;
  220.     if ($te eq "") { $umask += 1; }
  221.     if ($tw eq "") { $umask += 2; }
  222.     if ($tr eq "") { $umask += 4; }
  223.     if ($ge eq "") { $umask += 10; }
  224.     if ($gw eq "") { $umask += 20; }
  225.     if ($gr eq "") { $umask += 40; }
  226.     if ($oe eq "") { $umask += 100;}
  227.     if ($ow eq "") { $umask += 200; }
  228.     if ($or eq "") { $umask += 400; }
  229.     if ($umask < 100 && $umask > 9) { $umask = "0" . $umask; }
  230.     elsif ($umask < 10) { $umask = "00" . $umask; }
  231.     return $umask;
  232. }
  233.  
  234. sub getValues {
  235.     $val{'dto'} = $default_dto = 900;
  236.     $mto = $default_mto = 7200;
  237.     $val{'logf'} = $default_logf = "No";
  238.     $default_logf = "Yes";
  239.     $val{'eftp'} = "No";        # only set this to "Yes" if we find line
  240.  
  241.     $val{'or'} = "";    $val{'ow'} = "";    $val{'oe'} = "";
  242.     $val{'gr'} = "";    $val{'gw'} = "on";    $val{'ge'} = "";
  243.     $val{'tr'} = "";    $val{'tw'} = "on";    $val{'te'} = "";
  244.  
  245.     if (open(INETD, "< $conf")) {
  246.              while (<INETD>) {
  247.         @args = split(/\s+/);
  248.         if ($args[0] ne "ftp") { next; }
  249.         $val{'eftp'} = "Yes";
  250.         while ($arg = pop(@args)) {
  251.                 if ($arg eq "-l") { $val{'logf'} = "Yes"; }
  252.                 elsif (substr($arg,0,2) eq "-t") { $val{'dto'} = substr($arg,2); }
  253.                 elsif (substr($arg,0,2) eq "-T") { $mto = substr($arg,2); }
  254.                 elsif (substr($arg,0,2) eq "-u") { umask_to_args(substr($arg,2)); }
  255.             }
  256.         }
  257.     }
  258.  
  259.        close(INETD);
  260. }
  261.  
  262. sub generic {
  263.     &js_title_block($title,$js);
  264.     &header_block($title);
  265.  
  266.     print "<i>$message</i><br>";
  267.     print "<form name=\"StandardForm\" action=$myname method=post onSubmit=\"return runSubmit()\">";
  268.  
  269.     print "<center><table cellpadding=5 width=450>\n";
  270.  
  271.     print "<tr><th align=left>Enable FTP:</th><th align=left>",
  272.           &radio('eftp',$val{'eftp'},'Yes','No'),
  273.           "</th></tr>";
  274.  
  275.     if ($val{'dto'} == 900) { $val{'dto'} = ""; }
  276.     print "<tr><th align=left>Idle time before connection is dropped
  277.             (seconds):</th><th align=left>",
  278.           &text('dto', $val{'dto'},10),
  279.           "</th></tr>";
  280.  
  281. #    print '<TR><TH ALIGN="left">Maximum Inactivity Timeout (seconds)',
  282. #            '<TH ALIGN="left">';
  283. #    print &text('mto', $mto);
  284.  
  285.     print "<tr><th align=left>Log events in FTP sessions:</th><th align=left>",
  286.           &radio('logf',$val{'logf'},'Yes','No'),
  287.           "</th></tr>";
  288.  
  289.     print "<tr><th align=left>Permission settings for new files:",
  290.           "</th><th></th></tr>";
  291.  
  292.     print "</table></center>\n";
  293.  
  294.     if ($val{'or'} eq "") { $chor = "checked"; } else { $chor = ""; }
  295.     if ($val{'ow'} eq "") { $chow = "checked"; } else { $chow = ""; }
  296.     if ($val{'oe'} eq "") { $choe = "checked"; } else { $choe = ""; }
  297.  
  298.     if ($val{'gr'} eq "") { $chgr = "checked"; } else { $chgr = ""; }
  299.     if ($val{'gw'} eq "") { $chgw = "checked"; } else { $chgw = ""; }
  300.     if ($val{'ge'} eq "") { $chge = "checked"; } else { $chge = ""; }
  301.  
  302.     if ($val{'tr'} eq "") { $chtr = "checked"; } else { $chtr = ""; }
  303.     if ($val{'tw'} eq "") { $chtw = "checked"; } else { $chtw = ""; }
  304.     if ($val{'te'} eq "") { $chte = "checked"; } else { $chte = ""; }
  305.  
  306.     print "<center><table><tr><td></td><td>Owner</td><td>Group</td>
  307.             <td>Other</td></tr>";
  308.  
  309.     print "<tr><td>Read</td>";
  310.     print "<td>",qq|<input type="checkbox" name="or" $chor>|,"</td>";
  311.     print "<td>",qq|<input type="checkbox" name="gr" $chgr>|,"</td>";
  312.     print "<td>",qq|<input type="checkbox" name="tr" $chtr>|,"</td>";
  313.     print "</tr>";
  314.  
  315.     print "<tr><td>Write</td>";
  316.     print "<td>",qq|<input type="checkbox" name="ow" $chow>|,"</td>";
  317.     print "<td>",qq|<input type="checkbox" name="gw" $chgw>|,"</td>";
  318.     print "<td>",qq|<input type="checkbox" name="tw" $chtw>|,"</td>";
  319.     print "</tr>";
  320.  
  321.     print "<tr><td>Execute</td>";
  322.     print "<td>",qq|<input type="checkbox" name="oe" $choe>|,"</td>";
  323.     print "<td>",qq|<input type="checkbox" name="ge" $chge>|,"</td>";
  324.     print "<td>",qq|<input type="checkbox" name="te" $chte>|,"</td>";
  325.     print "</tr>";
  326.  
  327.     print "</table></center><br>";
  328.  
  329.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"',
  330.         "onClick=\"do_help('$help_page'); return (false)\"");
  331.  
  332.     print "</form>";
  333. }
  334.